/**
 *    Copyright (c) [2021] [白晓明]
 *    [IMHarmonyOSLib] is licensed under Mulan PSL v2.
 *    You can use this software according to the terms and conditions of the Mulan PSL v2.
 *    You may obtain a copy of Mulan PSL v2 at:
 *             http://license.coscl.org.cn/MulanPSL2
 *    THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *    See the Mulan PSL v2 for more details.
 */
package com.itming.ui.sample.slice;

import com.itming.ui.coptlib.core.IMButton;
import com.itming.ui.sample.ResourceTable;
import com.itming.ui.sample.UiLibLogin;
import com.itming.ui.sample.UiLibTitleAbility;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        //常规按钮
        IMButton imButton = (IMButton) findComponentById(ResourceTable.Id_btn);
        imButton.setClickedListener(l -> {
            present(new IMButtonAbilitySlice(), new Intent());
        });

        //图标按钮
        IMButton iconButton = (IMButton) findComponentById(ResourceTable.Id_icon_btn);
        iconButton.setClickedListener(l -> {
            present(new IMIconButtonAbilitySlice(), new Intent());
        });

        //UI-自定义标题栏
        IMButton uiTitleBar = (IMButton) findComponentById(ResourceTable.Id_ui_lib_title_bar);
        uiTitleBar.setClickedListener(l -> {
            // 这种方式跳转标题栏属性不会生效
            // present(new UiLibTitleAbilitySlice(), new Intent());
            Intent skipIntent = new Intent();

            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(UiLibTitleAbility.class)
                    .build();
            skipIntent.setOperation(operation);
            startAbility(skipIntent);
        });

        //UI-沉浸式登录
        IMButton uiLogin = (IMButton) findComponentById(ResourceTable.Id_ui_lib_login);
        uiLogin.setClickedListener(l -> {
//            present(new UiLibLoginSlice(), new Intent());
            Intent skipIntent = new Intent();

            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(UiLibLogin.class)
                    .build();
            skipIntent.setOperation(operation);
            startAbility(skipIntent);
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
